package com.sw.mygoogleplay.ui.activity;

import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import com.sw.mygoogleplay.R;
import com.sw.mygoogleplay.lib.PagerSlidingTab;

public class MainActivity extends AppCompatActivity {

    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle drawerToggle;
    private PagerSlidingTab slidingTab;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
        setActionBar();

    }

    /**
     * 初始化view
     */
    private void initViews() {
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        slidingTab = (PagerSlidingTab) findViewById(R.id.slidingTab);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
    }

    /**
     * 设置ActionBar
     */
    private void setActionBar() {
        //获取actionBar对象
        ActionBar actionBar = getSupportActionBar();
        //设置图标和标题
        actionBar.setIcon(R.drawable.ic_launcher_1);
        actionBar.setTitle(R.string.app_name);
        //启用ActionBar的home按钮
        actionBar.setDisplayHomeAsUpEnabled(true);//显示home按钮
        actionBar.setDisplayShowHomeEnabled(true);//可点击
        //将home的返回箭头替换为汉堡包按钮
        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer_am,0);
        drawerToggle.syncState();//同步
        //设置监听
        /*drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                drawerToggle.onDrawerSlide(drawerView,slideOffset);
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                drawerToggle.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                drawerToggle.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                drawerToggle.onDrawerStateChanged(newState);
            }
        });*/
        drawerLayout.setDrawerListener(drawerToggle);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        drawerToggle.onOptionsItemSelected(item);
        return super.onOptionsItemSelected(item);
    }
}
